package com.yjd.pub.system.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import com.yjd.comm.base.dao.IBaseDao;
import com.yjd.comm.base.service.impl.BaseServiceImpl;
import com.yjd.comm.system.model.AdminRoleInfoDto;
import com.yjd.comm.system.model.AdminRoleUserModel;
import com.yjd.comm.system.service.IAdminRoleUserService;
import com.yjd.pub.system.dao.IAdminRoleUserDao;

/**
 * <b>description</b>：管理员角色组关系服务实现<br>
 * <b>time</b>：2016-11-03 17:41:48 <br>
 * <b>author</b>： carl
 */
@Service("adminRoleUserService")
public class AdminRoleUserServiceImpl extends BaseServiceImpl implements
		IAdminRoleUserService {

	/**
	 * 插入
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	public AdminRoleUserModel insert(AdminRoleUserModel model) throws Exception {
		return this.adminRoleUserDao.insertModel(model, true);
	}

	/**
	 * 更新
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	public int update(AdminRoleUserModel model) throws Exception {
		return this.adminRoleUserDao.updateModel(model, true);
	}

	/**
	 * 根据id删除
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public int delete(long id) throws Exception {
		Map<Object, Object> paramMap = new HashMap<Object, Object>();
		paramMap.put("id", id);
		return this.adminRoleUserDao.deleteModel(paramMap, true);
	}

	@Override
	public List<AdminRoleInfoDto> getAdminRoleByIdList(Map<String, Object> param)
			throws Exception {

		return this.adminRoleUserDao.getAdminRoleByIdList(param);
	}

	@Override
	public Map<Long, List<AdminRoleInfoDto>> getAdminRoleBuyIds(
			Map<String, Object> param) throws Exception {
		Map<Long, List<AdminRoleInfoDto>> maps = new HashMap<Long, List<AdminRoleInfoDto>>();
		List<AdminRoleInfoDto> list = this.getAdminRoleByIdList(param);
		for (AdminRoleInfoDto roleInfo : list) {
			List<AdminRoleInfoDto> roleList = maps.get(roleInfo.getAdmin_id());

			if (roleList == null) {
				roleList = new ArrayList<AdminRoleInfoDto>();
				maps.put(roleInfo.getAdmin_id(), roleList);
			}
			roleList.add(roleInfo);
		}
		return maps;
	}

	
	
	@Override
	public void insertBatch(List<AdminRoleUserModel> List) throws Exception {
		  adminRoleUserDao.insertBatch(List, true);
	}



	@Resource
	private IAdminRoleUserDao adminRoleUserDao;

	@Override
	public IBaseDao getBaseDao() {
		return this.adminRoleUserDao;
	}

	@Override
	public int delete(Long admin_id) throws Exception {
		return adminRoleUserDao.delete(admin_id);
	}

}
